<extend name="Public/base"/>

<block name="body">
    <link rel="stylesheet" type="text/css" href="__CSS__/index.css">
    <link rel="stylesheet" type="text/css" href="__CSS__/upload.css">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <form action="" method="post" class="form-horizontal">
        <input type="hidden" name="id" id="id" value="{$data['ad_id']}">
        <div class="form-item">
            <label class="item-label">广告标题<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="ad_title" value="{$data['ad_title']}" placeholder="20字内">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">广告图片</label><span class="check-tips"></span>
            <div class="controls">
                <input type="file" name="upload_img" id="upload_img" >
                <a class="btn" href="javascript:;"  id="js-upload-img">上传</a>
                <input type="hidden" name="ad_img" value="{$data['ad_img']}" id="ad_img" >
            </div>
        </div>
        <div class="form-item">
            <img src="__ROOT__{$data['ad_img']}" id="img-data" style="<?php if(empty($data['ad_img'])):?>display:none;<?php endif;?>">

            <label class="item-label"></label><span class="check-tips"></span>
            <div class="controls">
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">内容:<span class="check-tips"></span></label>
            <div class="controls">
                <textarea rows="5" cols="20" id="content" class="textarea kind-editor"  name="ad_content" >{$data['ad_content']}</textarea>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">开始时间：<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" id="start_date" name="start_time" class="text input-4x" value="{$data['start_time']}" placeholder="开始时间" />
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">结束时间：<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" id="end_date" name="end_time" class="text input-4x" value="{$data['end_time']}" placeholder="结束时间" />
            </div>
        </div>

        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('ad / index')}');

        $('#start_date').datetimepicker({
            format: 'yyyy-mm-dd h:i:00',
            language: "zh-CN",
            minView: 0,
            autoclose: true
        });
        $('#end_date').datetimepicker({
            format: 'yyyy-mm-dd h:i:00',
            language: "zh-CN",
            minView: 0,
            autoclose: true
        });
    </script>

    <link rel="stylesheet" href="__PUBLIC__/static/kindeditor/default/default.css" />
    <script charset="utf-8" src="__PUBLIC__/static/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="__PUBLIC__/static/kindeditor/zh_CN.js"></script>

    <script type="text/javascript">

        KindEditor.ready(function (K) {
            window.editor = K.create('textarea[class="kind-editor"]', {
                //allowFileManager : false
                minWidth: 900,
                minHeight: 300,
                afterBlur: function () {
                    this.sync();
                },
            });
        });

        $("#js-upload-img").click(function () {
            var file = document.getElementById('upload_img');
            var fileList = file.files; //获取的图片文件 
            var filedata = fileList[0];
            var formData = new FormData();
            formData.append("download", filedata);

            $.ajax({
                url: "{:U('File/uploadImage')}",
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                success: function (data) {
                    $('#loading').hide();
                    if (data.status == 0) {

                        updateAlert(data.info);
                        setTimeout(function () {
                            $('#top-alert').find('button').click();
                            $(this).removeClass('disabled').prop('disabled', false);
                        }, 1500);
                        alert("上传失败!" + data.info);
                        return false;
                    } else {
                        $('#img-data').attr('src', '__ROOT__' + data.path);
                        $('#ad_img').val(data.path);
                        $('#img-data').show();
                    }
                },
                error: function () {
                    alert("上传失败！");
                    //                                $("#imgWait").hide();
                }
            });
        });


    </script>
</block>
